package com.lqk.shardingjdbcproj.controller;

import com.lqk.shardingjdbcproj.entity.Course;
import com.lqk.shardingjdbcproj.entity.User;
import com.lqk.shardingjdbcproj.entity.response.ReturnReponse;
import com.lqk.shardingjdbcproj.enums.ResponseEnum;
import com.lqk.shardingjdbcproj.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
public class UserController {

    @Autowired
    private UserService userService;

    // 水平分库
    @RequestMapping(value="/addUser",method = RequestMethod.POST)
    public ReturnReponse addUser(@RequestBody User user){
        int i = userService.insertCourse(user);
        if (i>0){
            return ReturnReponse.success(ResponseEnum.CODE_200.getCode(), ResponseEnum.CODE_200.getMessage());
        }else {
            return ReturnReponse.fail(ResponseEnum.CODE_400.getCode(), ResponseEnum.CODE_400.getMessage());
        }
    }

    @RequestMapping(value="/getUser",method = RequestMethod.POST)
    public ReturnReponse getUser(@RequestParam long userId){
        User user = userService.selectOne(userId);
        System.out.println(user.toString());
        return ReturnReponse.success(ResponseEnum.CODE_200.getCode(), ResponseEnum.CODE_200.getMessage(),user);
    }

}
